package com.jy.modules.cims.component.image.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jy.modules.cims.common.sysUtils.CollectionsUtils;
import com.jy.modules.cims.common.sysUtils.SimpleBeanUtils;
import com.jy.modules.cims.common.sysUtils.SpringContextUtils;
import com.jy.modules.cims.component.image.TransferImagesDao;
import com.jy.modules.cims.component.image.TransferImagesDto;
import com.jy.modules.cims.component.image.TransferImagesQueue;
import com.jy.modules.cims.data.dto.ImgurlDto;

/**
 * @description QueryTransferImagesService
 * @author shengzhoutao
 * @date 2015-09-29
 */
@Component
public class QueryTransferImagesService {
	
	private static Logger logger = LoggerFactory.getLogger(QueryTransferImagesService.class);

	@Autowired
	private SpringContextUtils springContextUtils;

	/**
	 * @description 放数据队列
	 * @return
	 */
	public int addDownQueue() {
		try {
			TransferImagesDao transferImagesDao = springContextUtils.getBean(TransferImagesDao.class);
			List<ImgurlDto> imgurlDtoList = transferImagesDao.getDealImg();
			if (CollectionsUtils.isEmpty(imgurlDtoList)) {
				return 0;
			}

			TransferImagesDto transferImagesDto = null;
			for (ImgurlDto imgurlDto : imgurlDtoList) {
				transferImagesDto = new TransferImagesDto();
				SimpleBeanUtils.copyBean2Bean(transferImagesDto, imgurlDto);

				TransferImagesQueue.downQueue.offer(transferImagesDto);
			}

			return imgurlDtoList.size();
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		
		return 0;
	}
}
